package com.yowasa.xiuxian.entity.bo;

import com.yowasa.xiuxian.engine.HoneEngine;
import com.yowasa.xiuxian.engine.hone.MentalInterface;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.exception.HandlerException;
import org.springframework.util.StringUtils;

/**
 * 消耗历练道行接口
 */
public interface CostTravelInterface extends ElementInterface {
    //提高的道行
    int upAbility();

    //基础所需历练
    int baseNeedTravel();

    default int userUpAbility(UserBO userBO) {
        String mentalStr = userBO.getUserConfig().getMental();
        if (StringUtils.isEmpty(mentalStr)) {
            throw new HandlerException("必须要运转心法才能学习战技");
        }
        MentalInterface mental = HoneEngine.mentalMap.get(mentalStr);
        if (mental.getElement() != null && !mental.getElement().judgeAdjust(getElement())) {
            return 2 * upAbility();
        }
        return upAbility();
    }

    default int needTravel(UserBO userBO) {
        String mentalStr = userBO.getUserConfig().getMental();
        if (StringUtils.isEmpty(mentalStr)) {
            throw new HandlerException("必须要运转心法才能学习战技");
        }
        MentalInterface mental = HoneEngine.mentalMap.get(mentalStr);
        if (mental.getElement() != null && !mental.getElement().judgeAdjust(getElement())) {
            return 2 * baseNeedTravel();
        }
        return baseNeedTravel();
    }


    /**
     * Y为技能0道行的时候的基础消耗。H为角色当前道行值
     * Y*(1+(H^2)/200)
     *
     * @param userBO
     * @return
     */
    default int calNeedTravel(UserBO userBO) {
        int Y = needTravel(userBO);
        int H = userBO.getUserConfig().getAbility() + userUpAbility(userBO);
        return (int) (Y * (1 + (H * H) / 200.0));
    }
}
